<!doctype html>
<script src="/resources/testdriver.js"></script>
<script src="/resources/testdriver-vendor.js"></script>
<script type="module">
import { buildValidNavigatorIdentityRequest, requestIdentityWithActivation } from './helper.js';

// Loading digital-identity-iframe.html in the test will make a digital credential call on load, and
// trigger a postMessage upon completion.
//
// message {
//   string result: "Pass" | "Fail"
//   string data: credential.token
//   string errorType: error.data
// }

window.onload = async () => {
  try {
    let request = buildValidNavigatorIdentityRequest();
    let credential = await requestIdentityWithActivation(test_driver, request);

    window.top.postMessage({result: "Pass", data: credential.data}, '*');
  } catch (error) {
    window.top.postMessage({result: "Fail", errorType: error.name}, '*');
  }
};

</script>
